package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PayWebController {

     @Autowired
     AlipayTemplate alipayTemplate;

     @Autowired
     OrderService orderService;

    /**
     * produces = "text/html"  明确告诉返回数据为 html   默认为  json
     * @return
     */
    @ResponseBody
    @GetMapping(path = "/aliPayOrder",produces = "text/html")
     public String goToPayOrder(@RequestParam String orderSn) throws AlipayApiException {
        PayVo payVo=orderService.getPayVoByOrdersn(orderSn);
        String pay = alipayTemplate.pay(payVo);
        return pay;
     }

}
